webpack.config.js ➔ ... ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 1
rs 10
1
const webpack = require('webpack');
2
const { join, resolve } = require('path');
3
const { getIfUtils, removeEmpty } = require('webpack-config-utils');
4
const ExtractTextPlugin = require('extract-text-webpack-plugin');
5
const AssetsPlugin = require('assets-webpack-plugin')
6
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
7
const WriteFilePlugin = require('write-file-webpack-plugin');
8
9
module.exports = (env) => {
10
    const { ifProd, ifNotProd } = getIfUtils(env);
11
12
    return {
13
        context: resolve(__dirname, './app/Resources/assets'),
14
        devtool: ifProd('source-map', 'cheap-module-source-map'),
15
        entry: {
16
            main: './main.js'
17
        },
18
        output: {
19
            path: resolve(__dirname, './web'),
20
            filename: ifProd('js/[name].[hash].js', 'js/[name].js'),
21
            pathinfo: ifNotProd(), // Include comments with information about the modules.
22
        },
23
        resolve: {
24
            extensions: ['.js'],
25
        },
26
        module: {
27
            rules: [
28
                {
29
                    test: require.resolve('jquery'),
30
                    use: [
31
                        {
32
                            loader: 'expose-loader',
33
                            query: 'jQuery'
34
                        },
35
                        {
36
                            loader: 'expose-loader',
37
                            query: '$'
38
                        }
39
                    ]
40
                },
41
                {
42
                    // Do not transform vendor's CSS with CSS-modules
43
                    // The point is that they remain in global scope.
44
                    test: /\.css$/,
45
                    include: /node_modules/,
46
                    loader: ExtractTextPlugin.extract({
47
                        fallback: 'style-loader',
48
                        use: {
49
                            loader: 'css-loader',
50
                            options: {
51
                                minimize: ifProd(),
52
                                sourceMap: true
53
                            }
54
                        }
55
                    })
56
                },
57
                {
58
                    test: /\.scss$/i,
59
                    loader: ExtractTextPlugin.extract({
60
                        fallback: 'style-loader',
61
                        use: [
62
                            {
63
                                loader: 'css-loader',
64
                                options: {
65
                                    minimize: ifProd(),
66
                                    sourceMap: true
67
                                }
68
                            }, {
69
                                loader: 'sass-loader'
70
                            }
71
                        ]
72
                    })
73
                },
74
                {
75
                    test: /\.(woff(2)?|eot|ttf|svg)(\?[a-z0-9=.]+)?$/,
76
                    use: 'file-loader?&publicPath=../fonts/&outputPath=fonts/&name=[name].[hash].[ext]'
77
                },
78
                {
79
                    test: /\.(gif|png|jpe?g|svg)$/i,
80
                    use: removeEmpty(
81
                        [
82
                            {
83
                                loader: 'url-loader',
84
                                query: {
85
                                    limit: 10 * 1000, // byte limit in bytes ( 10kb )
86
                                    hashType: 'sha512',
87
                                    digestType: 'hex',
88
                                    name: 'images/[name].[hash].[ext]',
89
                                }
90
                            },
91
                            ifProd(
92
                                {
93
                                    loader: 'image-webpack-loader',
94
                                    query: {
95
                                        progressive: true,
96
                                        optimizationLevel: 7,
97
                                        interlaced: false,
98
                                        pngquant: {
99
                                            quality: '65-90',
100
                                            speed: 4
101
                                        }
102
                                    }
103
                                }
104
                            )
105
                        ]
106
                    )
107
                },
108
            ]
109
        },
110
        plugins: removeEmpty([
111
            new webpack.LoaderOptionsPlugin({
112
                options: {
113
                    context: join(__dirname, 'web')
114
                }
115
            }),
116
            // write files to fs with webpack-dev-server
117
            new WriteFilePlugin(),
118
            new webpack.optimize.CommonsChunkPlugin({
119
                name: 'vendor',
120
                fileName: 'vendor.js',
121
                chunks: ['main'],
122
                minChunks: module => /node_modules\//.test(module.resource)
123
            }),
124
            new ExtractTextPlugin({
125
                filename: ifProd('css/[name].[contenthash].css', 'css/[name].css'),
126
                allChunks: true,
127
            }),
128
            ifProd(
129
                new AssetsPlugin({ path: join(__dirname, 'web', 'bundles') })
130
            ),
131
            ifProd(new webpack.optimize.UglifyJsPlugin({
132
                compress: {
133
                    screw_ie8: true,
134
                    warnings: false,
135
                },
136
                output: { comments: false }
137
            })),
138
            new ProgressBarPlugin(),
139
        ]),
140
    };
141
}
142